package gk.example.activity;

import gk.example.App;
import gk.example.BaseActivity;
import gk.example.bean.FeedBack;
import gk.example.util.T;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import cn.bmob.v3.listener.SaveListener;

import com.example.gkdate.R;

/**
 * 
 * Description:意见反馈界面
 * 
 * @author Wenk.Chan（最新修改者）
 * @version 1.0（最新版本号）
 */
public class FeedBackActivity extends BaseActivity implements OnClickListener {
	private TextView mTvTopTitle;
	private ImageButton mBtnBack;
	private EditText mEtContact;
	private EditText mEtContent;
	private Button mBtnSend;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	@Override
	protected void initView() {
		setContentView(R.layout.activity_feedback);
		mTvTopTitle = (TextView) findViewById(R.id.tv_top_title);
		mBtnBack = (ImageButton) findViewById(R.id.btn_back);
		mEtContact = (EditText) findViewById(R.id.et_feedback_contact);
		mEtContent = (EditText) findViewById(R.id.et_feedback_content);
		mBtnSend = (Button) findViewById(R.id.btn_feedback_send);
	}

	@Override
	protected void initEvent() {
		mTvTopTitle.setText(getResources().getString(R.string.feedback));
		mBtnBack.setOnClickListener(this);
		mBtnSend.setOnClickListener(this);
	}

	private void sendFeedBack() {
		String contact = mEtContact.getText().toString();
		String content = mEtContent.getText().toString();
		if (content.equals("")) {
			T.showShort(this, "您还没填写反馈信息");
			return;
		}
		FeedBack feedBack = new FeedBack();
		feedBack.setUserID(App.BmobUser.getObjectId());
		feedBack.setContact(contact);
		feedBack.setContent(content);
		feedBack.save(this, new SaveListener() {
			
			@Override
			public void onSuccess() {
				T.showShort(FeedBackActivity.this, "发送成功,谢谢您的宝贵意见");
				finish();
			}
			
			@Override
			public void onFailure(int arg0, String arg1) {
				T.showShort(FeedBackActivity.this, "发送失败"+arg1);
			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_back:
			finish();
			break;
		case R.id.btn_feedback_send:
			sendFeedBack();
			break;
		default:
			break;
		}
	}

}
